package com.axend.aerosense.room.ui.provider;

import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import androidx.databinding.DataBindingUtil;

import com.axend.aerosense.common.bean.WardSelectItemBean;
import com.axend.aerosense.room.ui.adapter.WardProviderMultiAdapter;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.axend.aerosense.room.R;
import com.axend.aerosense.room.databinding.RoomWardItemBinding;

import org.jetbrains.annotations.NotNull;

public class WardProvider extends BaseItemProvider<WardSelectItemBean> {
    private RoomWardItemBinding wardItemBinding;
    private boolean selectMode;

    public WardProvider(boolean selectMode) {
        this.selectMode = selectMode;
    }

    @Override
    public int getItemViewType() {
        return WardProviderMultiAdapter.TYPE_COMMON;
    }

    @Override
    public int getLayoutId() {
        return R.layout.room_ward_item;
    }

    @Override
    public void convert(@NotNull BaseViewHolder baseViewHolder, WardSelectItemBean bean) {
        // 获取 Binding
        wardItemBinding = baseViewHolder.getBinding();

        if (wardItemBinding != null) {
            wardItemBinding.setViewModel(bean);
            wardItemBinding.executePendingBindings();

            if(!TextUtils.isEmpty(bean.getWardImg())) {
                ImageView imageView = baseViewHolder.findView(R.id.room_user_head);
                Glide.with(imageView.getContext()).load(bean.getWardImg()).placeholder(R.mipmap.common_img_default_head)
                        .skipMemoryCache(true)
                        .diskCacheStrategy( DiskCacheStrategy.NONE ).circleCrop().into(imageView);
            }

        }
    }

    @Override
    public void onViewHolderCreated(@NotNull BaseViewHolder viewHolder, int viewType) {
        super.onViewHolderCreated(viewHolder, viewType);
        wardItemBinding = DataBindingUtil.bind(viewHolder.itemView);
        if(selectMode){
            wardItemBinding.roomWardCheck.setVisibility(View.VISIBLE);
        }else{
            wardItemBinding.roomWardCheck.setVisibility(View.GONE);
        }
    }
}
